<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    pageContext.setAttribute("PAGETITLE", "角色选择菜单");
%>
<%@ include file="/pages/include/header.jsp" %>

<script type="text/javascript">
<!--
function cmd(command, params) {
    switch (command) {
       case "confirm":
           var checkboxValues = $C.getCheckboxValues("check");
           var roleId = $E("roleId").value;
           var url = ctx + "/action/roleMenu.do";
           $.post(url, {method: "insert", roleId: roleId, menuIds: checkboxValues.toString()}, function (returnString) {
               var i = parseInt(returnString);
               if (0 < i) {
                   $("#action_result").html("操作成功");
                   $("#action_result").addClass("action_result_1");
               } else {
                   $("#action_result").html("操作失败");
                   $("#action_result").addClass("action_result_0");
               }
               $C.showTips({selector: "#action_result", position: $C.P_LEFT, hide: true});
           });
           break;
    }
}

$(document).ready(function () {
    $("#action_result").animate({left: -100}, 0);
});
//-->
</script>

<sql:query var="roleMenuList" dataSource="${dataSource}">
SELECT M.*, (CASE WHEN M.STATUS = '1' THEN '有效' ELSE '无效' END) STATUS2,
    (CASE WHEN RM.ROLEID IS NULL THEN '' ELSE 'checked="checked"' END) CHECKED
FROM CT_MENU M
    LEFT JOIN CT_ROLEMENU RM ON M.MENUID = RM.MENUID AND RM.ROLEID = '${param.roleId}'
ORDER BY M.ORDERNO
</sql:query>

<body>

    <input type="hidden" id="roleId" value="${param.roleId}" />

    <div class="page_header">${PAGETITLE}</div>
    
    <div class="page_buttons">
        <div id="action_result" class="action_result"></div>
        <input type="button" value="确定" onclick="cmd('confirm')" />
    </div>
    
    <div class="page_query">
        query div
    </div>

    <br />
    <table cellpadding="0" cellspacing="0" align="center" class="table_list">
        <thead>
            <tr>
                <td>&nbsp;</td>
                <td width="45">序号</td>
                <td>菜单名称</td>
                <td>链接地址</td>
                <td width="65">是否有效</td>
                <td width="60">排序号</td>
            </tr>
        </thead>
        <tbody>
            <c:forEach var="item" items="${roleMenuList.rows}" varStatus="vs">
            <tr>
                <td><input type="checkbox" name="check" value="${item.MENUID}" ${item.CHECKED} /></td>
                <td align="center">${vs.index + 1}</td>
                <td align="left">&nbsp;${item.MENUNAME}</td>
                <td align="left">&nbsp;${item.MENUURL}</td>
                <td align="center">&nbsp;${item.STATUS2}</td>
                <td align="right">&nbsp;${item.ORDERNO}</td>
            </tr>
            </c:forEach>
        </tbody>
    </table>
    
    <div class="page_footer"></div>

</body>

<%@ include file="/pages/include/footer.jsp" %>
